package com.example.practice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends Activity {

    private ListView mian2;
    private List<Car6Users> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        list = new ArrayList<>();
        Car6Users car6Users = new Gson().fromJson(name, Car6Users.class);
        list.add(car6Users);
        mian2.setAdapter(new myAdapter());
    }

    private void initView() {
        mian2 = (ListView) findViewById(R.id.mian2);
    }
    private class myAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return list.get(0).getData().get(0).getLog().size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View view1 = View.inflate(Main2Activity.this,R.layout.top1,null);
            TextView textView = view1.findViewById(R.id.rrrr);
            textView.setText(
                    list.get(0).getData().get(0).getCarNo()+"\n"+
                    list.get(0).getData().hashCode()+"\n"+
                    list.get(0).getData().get(0).getLog().get(i).getAddress()+"\n"+
                    list.get(0).getData().get(0).getLog().get(i).getFee()+"\n"+
                    list.get(0).getData().get(0).getLog().get(i).getReason()
            );
            return view1;
        }
    }
}
